<#assign ctx=springMacroRequestContext.contextPath />
<#include "/macro/publicMacro.ftl">
<#import "/macro/pagination.ftl" as Pagination>
<#import "/macro/FormItem.ftl" as Form>

<@header title="角色编辑">
</@header>

<@body>
    <h2 class="module-title"><#if role.id??>编辑角色</#if><#if !(role.id??)>添加角色</#if></h2>

    <div class="alert alert-primary" role="alert">
        <#--<button class="btn btn-info" onclick="javascript: history.back(-1);return false;">返回</button>-->
        <a class="btn btn-info btn-sm" href="${ctx}/role/list" role="button" aria-pressed="true">返回</a>
    </div>

    <#if error??>
    <div class="alert alert-danger" role="alert">
        <span>${error}</span>
    </div>
    </#if>

    <form class="form-horizontal" id="roleForm" action="${ctx}/role/save" method="post">
        <input type="hidden" name="id" id="id" value="${role.id}"/>
        <@Form.FormItem name="name" label="角色名称">
            <input type="text" class="form-control" name="name" id="name" aria-describedby="角色名称" value="${role.name}">
        </@Form.FormItem>
        <@Form.FormItem name="description" label="描述">
            <input type="text" class="form-control" name="description" id="description" aria-describedby="描述" value="${role.description}">
        </@Form.FormItem>
        <@Form.FormItem name="status" label="状态">
            <select class="form-control" name="status" id="status">
                <#list statusValues as status>
                    <option value="${status}" <#if status == role.status>selected</#if>>${status.desc}</option>
                </#list>
            </select>
        </@Form.FormItem>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-primary">提交</button>
            </div>
        </div>
    </form>
</@body>

<@footer>
    <script src="${ctx}/resource/common/js/jquery.validate.min.js"></script>
    <script src="${ctx}/resource/common/js/validate.message.cn.js"></script>
    <script src="${ctx}/resource/common/js/additional-methods.min.js"></script>

    <script type="text/javascript">
        $().ready(function () {
            $("#roleForm").validate({
                rules: {
                    id: {
                        required: true,
                        digits: true
                    },
                    <#--name: {-->
                    <#--    required: true,-->
                    <#--    remote: {-->
                    <#--        url: "${ctx}/role/checkName/json",-->
                    <#--        type: "get",-->
                    <#--        data: {-->
                    <#--            id: function () {-->
                    <#--                return $("#id").val();-->
                    <#--            },-->
                    <#--            moduleId: function() {-->
                    <#--                return $("#module-id").val();-->
                    <#--            }-->
                    <#--        }-->
                    <#--    }-->
                    <#--},-->
                    'moduleId.id': {
                        required: true,
                        digits: true
                    },
                    description: {
                        required: true,
                        maxlength: 128
                    },
                    status: "required"
                },
                messages: {
                    name:  {
                        required: '角色名称不能为空',
                        remote: '角色名重复'
                    }
                }
            });
        });
    </script>
</@footer>